<template>
	<view class="p-20">
		<view class="bg-white p-30 border-radius">
			<view class="form-item mb-40">
				<view class="font-bold font-28">姓名</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.username" placeholder="请输入" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">手机号</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.mobile" placeholder="请输入" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">性别</view>
				<view class="mt-20">
					<uni-data-checkbox v-model="form.sex" :localdata="sex_enum" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">电子邮箱</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.email" placeholder="请输入" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">出生年月</view>
				<view class="mt-20">
					<uni-datetime-picker type="date" :value="form.birthday" returnType="string" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">工作时间</view>
				<view class="mt-20">
					<uni-datetime-picker type="date" :value="form.workTime" returnType="string" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">居住城市</view>
				<view class="mt-20">
					<uni-data-select v-model="form.homeCity" :localdata="city_enum"></uni-data-select>
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">政治面貌</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.political" placeholder="请输入" />
				</view>
			</view>
			<!-- <view class="form-item mb-40">
				<view class="font-bold font-28">求职状态</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.applyStatus" placeholder="请输入" />
				</view>
			</view> -->
			<view class="form-item mb-40">
				<view class="font-bold font-28">自我介绍</view>
				<view class="mt-20">
					<uni-easyinput type="textarea" v-model="form.selfIntroduction" placeholder="请输入" />
				</view>
			</view>
		</view>
		<view class="bottom-view">
			<view class="bottom-btn font-white bg-g" @click="submit">保存</view>
		</view>
	</view>
</template>

<script>
	import {
		getInfo, add, edit
	} from '../../api/apply_user';
	export default {
		data() {
			return {
				sex_enum: [{
						text: '男',
						value: 1
					},
					{
						text: '女',
						value: 2
					}
				],
				city_enum: [
					{
						text: '东营市',
						value: '东营市'
					},{
						text: '东营区',
						value: '东营区'
					},{
						text: '河口区',
						value: '河口区'
					},{
						text: '垦利区',
						value: '垦利区'
					},{
						text: '广饶县',
						value: '广饶县'
					},{
						text: '利津县',
						value: '利津县'
					}
				],
				form: {},
				first: true
			};
		},
		onLoad() {
			this.getDetail()
		},
		methods: {
			getDetail() {
				const _this = this
				getInfo().then(res => {
					if (res.code === 200) {
						this.form = res.result
						this.first = false
					} 
				})
			},
			submit() {
				const _this = this
				this.$tips.showModal('是否提交职位信息？', () => {
					// _this.$tips.showConfirmModal('提交成功，请等待审核', () => {
					// 	uni.navigateBack()
					// })
					if (this.first) {
						add({...this.form}).then(res => {
							if (res.code === 200) {
								_this.$tips.showConfirmModal('提交成功，请等待审核', () => {
									uni.navigateBack()
								})
							} else {
								_this.$tips.showConfirmModal('提交失败，请重试', () => {
								})
							}
						})
					} else {
						edit({...this.form}).then(res => {
							if (res.code === 200) {
								_this.$tips.showConfirmModal('提交成功，请等待审核', () => {
									uni.navigateBack()
								})
							} else {
								_this.$tips.showConfirmModal('提交失败，请重试', () => {
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
	}

	.bottom-view {
		width: 100vw;
		padding: 40rpx 0;
		background-color: #fff;
		border-top: 1px solid #efefef;

		.bottom-btn {
			width: 80vw;
			margin: auto;
			text-align: center;
			border-radius: 50rpx;
			padding: 20rpx 0;
		}
	}
</style>